﻿using UnityEngine;
using System.Collections;

/*
 * 受击计算的模拟模块
 * 
 */ 
public class DeathEvent : System.EventArgs
{

}


public class Body : MonoBehaviour {

	public BoxCollider bodyColli;
	public Square mainSquare;
	public CommonProperty prop;

	public event System.EventHandler<DeathEvent> evtDeath;

	// Use this for initialization
	void Start () {

	}
	
	// Update is called once per frame
	void Update () {
	
	}

	public void OnHit (HitEvent evt)
	{
		prop.healthPoint -= evt.dmgInfo.damage;

		if (prop.healthPoint < 0 && evtDeath != null)
			evtDeath (this, new DeathEvent ());
	}
	
	void OnTriggerEnter(Collider colli) {

		if (colli.gameObject.tag == "AttackRange" &&
		    mainSquare.GetComponent<Camp>().camp != colli.gameObject.GetComponent<Camp>().camp)
		{
			HitCaculate.CaculateHit(this, colli.gameObject.GetComponent<HitAction>());
		}
	}

	/*void OnCollisionEnter(Collision colli) {
		Debug.Log ("OnCollisionEnter");
		foreach (ContactPoint contact in colli.contacts) {

			if (contact.otherCollider.gameObject.tag == "WarningRange")
			{
				HitCaculate.CaculateHit(this, contact.otherCollider.gameObject.GetComponent<HitAction>());
			}
		}
	}*/
}
